package com.xyhs.b2c.oauth.service.impl;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.security.oauth2.provider.client.BaseClientDetails;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.Map;

/**
 * @apiNote  自定义客户端实现
 * @author DELL
 */

@Service("myClientDetailsServiceImpl")
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class MyClientDetailsServiceImpl extends JdbcClientDetailsService {


    public MyClientDetailsServiceImpl(DataSource dataSource) {
        super(dataSource);
    }

    @Override
    public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException {
        BaseClientDetails baseClientDetails = (BaseClientDetails) super.loadClientByClientId(clientId);
        Map<String, Object> information = baseClientDetails.getAdditionalInformation();
        log.info("获取的自定义client的information为{}",JSONObject.toJSONString(information));
        log.info("获取的自定义client为{}",baseClientDetails);
        return baseClientDetails;
    }
}
